# coding:utf-8
from sqlalchemy import Column, String, Integer, Text, orm

from app.models.base import Base

__author__ = '七月'


class Book(Base):
    __tablename__='book'
    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键')
    douban_id = Column(String(15), nullable=False, unique=True, comment='豆瓣ID')
    douban_url = Column(String(200), default='', comment='豆瓣链接')
    douban_rating = Column(String(11), default='', comment='豆瓣评分')
    douban_count = Column(String(11), default='', comment='评分人数')
    isbn = Column(String(15), nullable=False, unique=True, comment='ISBN')
    title = Column(String(50), nullable=False, comment='书名')
    cover = Column(String(50), comment='封面')
    author = Column(String(30), default='未名', comment='作者')
    binding = Column(String(20), comment='装帧')
    publisher = Column(String(50), comment='出版社')
    price = Column(String(20), comment='定价')
    pages = Column(Integer, comment='页数')
    publish_date = Column(String(20), comment='出版日期')
    summary = Column(Text(), comment='简介')
    catalogue = Column(Text(), comment='目录')
    # tags = Column(String(100), comment='标签')

    @orm.reconstructor
    def __init__(self):
        self.fields = ['id', 'title', 'author', 'binding',
                       'publisher',
                       'price', 'pages', 'pubdate', 'isbn',
                       'summary',
                       'image']
